<?php
	require_once "gameAPI.php";
	
	$user_id = get_user_id();
	//$user_id = "3";
	
	$factory_id = get_my_factory_id($user_id);
	
	$new_user = 0;
		
	if (! $factory_id) 
	{
		add_new_user($user_id);
		$new_user = 1;
	}
?>
<html>
<head>
<title>Welcome FrenFactory</title>

<style type="text/css">

#canvas
{
	width:745px;
	height:760px;
	top:0px;
	left:0px;
	position:absolute;
}

#smoke
{
	position:absolute;
	top:280px;
	left:220px;
}

#factory
{
	position:absolute;
	top:350px;
	left:220px;
}

#frenfactory
{
	position:absolute;
	top:220px;
	left:220px;
}

</style>

<script type="text/javascript">

var smoke = null;

var new_user_flag = <?php echo $new_user; ?>;

var factory_id = <?php echo $factory_id; ?>

function animate()
{
    smoke.style.left = parseInt(smoke.style.left) - 1 +'px';
	smoke.style.top = parseInt(smoke.style.top) - 1 + 'px';
	if (parseInt(smoke.style.left) < 190)
	{
	    smoke.style.left = '220px';
		smoke.style.top = '280px';
	}
	t = setTimeout(animate, 20);
}

function init()
{
	smoke = document.getElementById('smoke');
	if (new_user_flag == 1) 
	{
		//alert("go help page");
		window.location.href= "help.php" ;
	}
	else
	{
		//alert("go factory page");
		window.location.href= "factory.php" ;
	}
	animate();
}

window.onload = init;



</script>

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-25431105-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

</head>

<body>
<div id="canvas">
	<div id="factory">
		<img id src="images/Index/Factory picture.png">
	</div>
	<div>
		<img id="smoke" style="top:280px; left:220px;" src="images/Index/Smoke clouds.png">
	</div>
	<div id="frenfactory">
		<img src="images/Index/FrenFactory.png">
	</div>
</div>
</body>

</html>
